package org.or5e.api.bm.server;

import java.util.HashMap;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class DummyServer extends SMTPServer {
	private static final long serialVersionUID = 1L;

	public DummyServer(String hostName) {
		//this(hostName, "ponraj.1978", "143jesus", Boolean.TRUE);
		this(hostName, "", "", Boolean.FALSE);
		setServerName("Localhost");
	}
	public DummyServer(String hostName, String userName, String passWd, Boolean authentication) {
		super(hostName, userName, passWd, authentication);
	}

	@Override
	public boolean sendMail(HashMap<String, String> header, String sender,
			String replyTo, String receipt, String subject, String message) {
		return false;
	}

	@Override
	public boolean sendMail(HashMap<String, String> header, String sender,
			String receipt, String subject, String message) {
		return false;
	}

	@Override
	public boolean sendMail(String sender, String receipt, String subject,
			String message) {
		return sendMail(sender, receipt, sender, subject, message);
	}

	@Override
	public boolean sendMail(String sender, String replyTo, String receipt,
			String subject, String message) {
		Message mailMessage = new MimeMessage(this.mailSession);
		try {
			mailMessage.setFrom(new InternetAddress(sender));
			mailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(receipt));
			mailMessage.setSubject(subject);
	        mailMessage.setText(message);
	        Transport.send(mailMessage);
		} 
		catch (AddressException e) {
			e.printStackTrace();
			return false;
		} 
		catch (MessagingException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
	@Override
	public String getName() {
		return "DummyServer";
	}
}
